package cn.kgc.ssm.controller;

import cn.kgc.ssm.dto.TbAddressPageDTO;
import cn.kgc.ssm.entity.TbAddress;
import cn.kgc.ssm.service.TbAddressService;
import cn.kgc.ssm.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: hengge
 * @version: v1.0
 * @DATE: 2022/10/22
 */
@RestController   //json格式
@RequestMapping("user")
public class TbAddressController {
    @Autowired
    private TbAddressService tbAddressService;

    //1.查询所有和条件(搜索功能)查询
    @RequestMapping("all")
    public Result search(TbAddressPageDTO userPageDTO){
        Result result = tbAddressService.search(userPageDTO);
        return result;
    }

    //2.添加用户信息
    @RequestMapping("add")
    public Result add(@RequestBody TbAddress tbAddress){
        System.out.println(tbAddress); //测试能不能打印user的信息
        Result result = tbAddressService.add(tbAddress);
        return result;
    }

    //3.编辑用户信息
    // 以json格式的数据方式修改用户信息
    @RequestMapping("update")
    public Result update(@RequestBody TbAddress tbAddress){
        System.out.println(tbAddress);
        Result result = tbAddressService.update(tbAddress);
        return  result;
    }

    //4.删除或批量删除用户信息
    @RequestMapping("delete")
    public Result deleteMore(String ids){
        String[] IdArray = ids.split(",");
        return  tbAddressService.deleteMore(IdArray);
    }
}
